<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
	<title>Document</title>
	<script type="text/javascript">
	//html里怎么写,js里就怎么写
       window.onload=function (){
            //var a=document.getElementsByTagName("input");
            var a=document.getElementById("div1");
            var c=a.getElementsByTagName("input");
            var btn1=document.getElementById("btn1");
            var btn2=document.getElementById("btn2");
            var btn3=document.getElementById("btn3");
          btn1.onclick=function (){
               for(var i=0;i<=c.length;i++){
                  // alert(c.length);
                 c[i].checked=true;
               }
            }
                btn2.onclick=function (){
               for(var i=0;i<=c.length;i++){
                  // alert(c.length);
                 c[i].checked=false;
               }
                }
          //   for(var i=0;i<=c.length;i++){
          //        if(c[i].checked==false){
          //         c[i].checked=true;
          //        }else{
          //         c[i].checked=false;
          //        }
          //   }
          // }
               btn3.onclick=function (){
                  for(var i=0;i<c.length;i++){
                     if(c[i].checked==true){
                        c[i].checked=false;
                     }else{
                        c[i].checked=true;
                     }
                  }
               }
         
       }
	</script>
</head>
<body>
   <input id="btn1" type="button" value="全选"><br>
   <input id="btn2"
    type="button" value="全不选"><br> 
     <input id="btn3" type="button" value="反选"><br>
   <div id="div1">  
   <input type="checkbox"><br>
   <input type="checkbox"><br>
   <input type="checkbox"><br>
   <input type="checkbox"><br>
   <input type="checkbox"><br>
   <input type="checkbox"><br>
   <input type="checkbox"><br>
   <input type="checkbox"><br>
   <input type="checkbox"><br>
   </div>

</body>
</html>